package com.bh.ly.oa.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import com.bh.ly.oa.R;


/**
 * 通用WebView
 * 
 * @author fancy
 * 
 */
public class WebViewActivity extends Activity {
	private WebView webView;
	private LinearLayout progressBar;
//	private TextView title;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_webview);
		initView();
		initData();
	}

	private void initView() {
		webView = (WebView) findViewById(R.id.webview);
		progressBar = (LinearLayout) findViewById(R.id.linearlayout_progressbar);
//		title = (TextView) findViewById(R.id.title_textview);
	}

	private void initData() {
		webView.setFocusable(true);
		webView.requestFocus();
		webView.clearCache(true);
		webView.setInitialScale(1);// webView网页缩放 参数是百分比
		webView.getSettings().setUseWideViewPort(true);//
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setSupportZoom(true);
		webView.getSettings().setBuiltInZoomControls(true);
		webView.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				// TODO Auto-generated method stub
				progressBar.setVisibility(View.VISIBLE);
				super.onPageStarted(view, url, favicon);
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				webView.setInitialScale(1);
				progressBar.setVisibility(View.INVISIBLE);
				super.onPageFinished(view, url);
			}

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// 禁用链接返回true
				// view.loadUrl(url);

				if (url.startsWith("tel:")) {
					Intent intent = new Intent(Intent.ACTION_CALL, Uri
							.parse("tel:" + url));
					WebViewActivity.this.startActivity(intent);
				}

				return false;
			}
		});
		
		String url = getIntent().getStringExtra("url");
		if (!TextUtils.isEmpty(url)) {
			webView.loadUrl(url);
		} else {
			finish();
		}
//		String titleStr = getIntent().getStringExtra("title");
//		if (!TextUtils.isEmpty(url)) {
//			title.setText(titleStr);
//		}
	}


}
